#include "Perso.h"

using namespace std;

Perso::Perso()//Constructeur
{
    m_image = IMG_Load("link.png");
    m_ScreenPos.x = 400;
    m_ScreenPos.y = 300;
    vect.setPos(400, 300);
    m_right = false;
    m_left = false;
    m_up = false;
    m_down = false;
}

void Perso::Update(graphics* graphs)//Fonction Draw
{
    //directions booleans : true = begin movement | false = stopping movement
    if (m_right && !m_left)      //right
        vect.changePos(6, 0);
    else if (m_left && !m_right) //left
        vect.changePos(-6, 0);
    if (m_up && !m_down)         //up
        vect.changePos(0, -6);
    else if (m_down && !m_up)    //down
        vect.changePos(0, 6);

    m_ScreenPos.x = vect.getX();
    m_ScreenPos.y = vect.getY();
    graphs->drawImage(m_image, &m_ScreenPos);
}

void Perso::move (bool state, string direction)
{
    //state : true = begin movement | false = stopping movement
    if (direction == "right")
        m_right = state;
    else if (direction == "left")
        m_left = state;
    else if (direction == "up")
        m_up = state;
    else if (direction == "down")
        m_down = state;
    else
        cerr << "erreur, le paramètre \"" << direction << "\" n'est pas un paramètre valide pour la fonction Perso.move" << endl;
}
